<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>越南时事新闻汉越双语平行语料库 - 用户登录</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
            background: #f5f5f5;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 顶部导航栏 */
        .header {
            background: #c41e3a;
            color: white;
            padding: 0 20px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .logo {
            display: flex;
            align-items: center;
            font-size: 18px;
            font-weight: bold;
        }

        .logo::before {
            content: "🏛️";
            margin-right: 8px;
            font-size: 20px;
        }

        .header-title {
            font-size: 16px;
            opacity: 0.9;
        }

        /* 主内容区域 */
        .main-container {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 40px 20px;
            position: relative;
        }

        /* 背景装饰 */
        .bg-decoration {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: 
                radial-gradient(circle at 20% 20%, rgba(196, 30, 58, 0.05) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(255, 215, 0, 0.05) 0%, transparent 50%);
            pointer-events: none;
        }

        /* 左侧插图区域 */
        .illustration-section {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            max-width: 600px;
            margin-right: 60px;
        }

        .illustration {
            width: 100%;
            max-width: 500px;
            height: 400px;
            background: #c41e3a;
            border-radius: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(196, 30, 58, 0.2);
        }

        .illustration::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: 
                radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
                radial-gradient(circle at 70% 70%, rgba(255, 215, 0, 0.1) 0%, transparent 50%);
        }

        .illustration-content {
            position: relative;
            z-index: 2;
            text-align: center;
            color: white;
        }

        .illustration-icon {
            font-size: 80px;
            margin-bottom: 20px;
            text-shadow: 0 2px 4px rgba(0,0,0,0.3);
            animation: float 3s ease-in-out infinite;
        }

        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }

        /* 添加装饰性元素 */
        .decoration-elements {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            pointer-events: none;
        }

        .decoration-circle {
            position: absolute;
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            animation: rotate 20s linear infinite;
        }

        .decoration-circle:nth-child(1) {
            width: 60px;
            height: 60px;
            top: 20%;
            left: 10%;
            animation-delay: 0s;
        }

        .decoration-circle:nth-child(2) {
            width: 40px;
            height: 40px;
            top: 60%;
            right: 15%;
            animation-delay: -5s;
        }

        .decoration-circle:nth-child(3) {
            width: 80px;
            height: 80px;
            bottom: 20%;
            left: 20%;
            animation-delay: -10s;
        }

        @keyframes rotate {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* 添加浮动粒子效果 */
        .particle {
            position: absolute;
            width: 4px;
            height: 4px;
            background: rgba(255, 255, 255, 0.6);
            border-radius: 50%;
            animation: particle-float 6s ease-in-out infinite;
        }

        .particle:nth-child(1) { top: 10%; left: 20%; animation-delay: 0s; }
        .particle:nth-child(2) { top: 30%; right: 25%; animation-delay: -1s; }
        .particle:nth-child(3) { bottom: 30%; left: 30%; animation-delay: -2s; }
        .particle:nth-child(4) { bottom: 10%; right: 20%; animation-delay: -3s; }
        .particle:nth-child(5) { top: 50%; left: 10%; animation-delay: -4s; }

        @keyframes particle-float {
            0%, 100% { 
                transform: translateY(0px) scale(1);
                opacity: 0.6;
            }
            50% { 
                transform: translateY(-20px) scale(1.2);
                opacity: 1;
            }
        }

        .illustration-title {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 10px;
            text-shadow: 0 2px 4px rgba(0,0,0,0.3);
        }

        .illustration-subtitle {
            font-size: 16px;
            opacity: 0.9;
            text-shadow: 0 1px 2px rgba(0,0,0,0.3);
        }

        /* 登录表单区域 */
        .login-section {
            width: 400px;
            background: white;
            border-radius: 12px;
            box-shadow: 0 8px 32px rgba(0,0,0,0.1);
            padding: 40px;
            position: relative;
        }

        .login-section::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: #c41e3a;
            border-radius: 12px 12px 0 0;
        }

        .login-title {
            text-align: center;
            margin-bottom: 30px;
        }

        .login-title h1 {
            font-size: 24px;
            color: #c41e3a;
            margin-bottom: 8px;
            font-weight: bold;
        }

        .login-title p {
            color: #666;
            font-size: 14px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: 500;
            font-size: 14px;
        }

        .form-input {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e0e0e0;
            border-radius: 8px;
            font-size: 14px;
            transition: all 0.3s ease;
            background: #fafafa;
        }

        .form-input:focus {
            outline: none;
            border-color: #c41e3a;
            background: white;
            box-shadow: 0 0 0 3px rgba(196, 30, 58, 0.1);
        }

        .form-input::placeholder {
            color: #999;
        }

        .login-button {
            width: 100%;
            padding: 14px;
            background: #c41e3a;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-bottom: 20px;
        }

        .login-button:hover {
            background: #a0172e;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(196, 30, 58, 0.3);
        }

        .login-button:active {
            transform: translateY(0);
        }

        .register-link {
            text-align: center;
        }

        .register-link a {
            color: #c41e3a;
            text-decoration: none;
            font-size: 14px;
            font-weight: 500;
            transition: color 0.3s ease;
        }

        .register-link a:hover {
            color: #a0172e;
            text-decoration: underline;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .main-container {
                flex-direction: column;
                padding: 20px;
            }

            .illustration-section {
                margin-right: 0;
                margin-bottom: 40px;
                max-width: 100%;
            }

            .illustration {
                height: 300px;
            }

            .illustration-icon {
                font-size: 60px;
            }

            .illustration-title {
                font-size: 20px;
            }

            .login-section {
                width: 100%;
                max-width: 400px;
            }
        }

        /* 加载动画 */
        .loading {
            display: none;
            text-align: center;
            margin-top: 20px;
        }

        .loading-spinner {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 2px solid #f3f3f3;
            border-top: 2px solid #c41e3a;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* 错误提示 */
        .error-message {
            background: #fee;
            color: #c41e3a;
            padding: 10px;
            border-radius: 6px;
            margin-bottom: 20px;
            font-size: 14px;
            border-left: 4px solid #c41e3a;
            display: none;
        }

        /* 成功提示 */
        .success-message {
            background: #efe;
            color: #2d5a2d;
            padding: 10px;
            border-radius: 6px;
            margin-bottom: 20px;
            font-size: 14px;
            border-left: 4px solid #2d5a2d;
            display: none;
        }
    </style>
</head>
<body>
    <!-- 顶部导航栏 -->
    <header class="header">
        <div class="logo">
            <span>越南时事新闻汉越双语平行语料库</span>
        </div>
        <div class="header-title">用户登录</div>
    </header>

    <!-- 主内容区域 -->
    <main class="main-container">
        <div class="bg-decoration"></div>
        
        <!-- 左侧插图区域 -->
        <section class="illustration-section">
            <div class="illustration">
                <!-- 装饰性元素 -->
                <div class="decoration-elements">
                    <div class="decoration-circle"></div>
                    <div class="decoration-circle"></div>
                    <div class="decoration-circle"></div>
                    <div class="particle"></div>
                    <div class="particle"></div>
                    <div class="particle"></div>
                    <div class="particle"></div>
                    <div class="particle"></div>
                </div>
                
                <div class="illustration-content">
                    <div class="illustration-icon">📚</div>
                    <div class="illustration-title">汉越双语语料库</div>
                    <div class="illustration-subtitle">专业的越南时事新闻双语平行语料管理平台</div>
                </div>
            </div>
        </section>

        <!-- 登录表单区域 -->
        <section class="login-section">
            <div class="login-title">
                <h1>帐号密码登录</h1>
                <p>请输入您的用户名和密码</p>
            </div>

            <!-- 错误提示 -->
            <div class="error-message" id="errorMessage"></div>
            
            <!-- 成功提示 -->
            <div class="success-message" id="successMessage"></div>

            <form id="loginForm">
                <div class="form-group">
                    <label class="form-label" for="username">用户名</label>
                    <input 
                        type="text" 
                        id="username" 
                        name="username" 
                        class="form-input" 
                        placeholder="请输入用户名或邮箱"
                        required
                    >
                </div>

                <div class="form-group">
                    <label class="form-label" for="password">密码</label>
                    <input 
                        type="password" 
                        id="password" 
                        name="password" 
                        class="form-input" 
                        placeholder="请输入密码"
                        required
                    >
                </div>

                <button type="submit" class="login-button">
                    登录
                </button>
            </form>

            <div class="register-link">
                <a href="register.html">帐号注册</a>
            </div>

            <!-- 加载动画 -->
            <div class="loading" id="loading">
                <div class="loading-spinner"></div>
                <span style="margin-left: 10px;">登录中...</span>
            </div>
        </section>
    </main>

    <script>
        // 登录表单处理
        document.getElementById('loginForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const username = document.getElementById('username').value.trim();
            const password = document.getElementById('password').value.trim();
            const errorMessage = document.getElementById('errorMessage');
            const successMessage = document.getElementById('successMessage');
            const loading = document.getElementById('loading');
            const loginButton = document.querySelector('.login-button');
            
            // 隐藏之前的消息
            errorMessage.style.display = 'none';
            successMessage.style.display = 'none';
            
            // 基本验证
            if (!username || !password) {
                showError('请输入用户名和密码');
                return;
            }
            
            // 显示加载状态
            loading.style.display = 'block';
            loginButton.disabled = true;
            loginButton.textContent = '登录中...';
            
            try {
                const response = await fetch('/auth/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        username: username,
                        password: password
                    })
                });
                
                const result = await response.json();
                
                if (response.ok && result.code === 200) {
                    // 登录成功
                    showSuccess('登录成功，正在跳转...');
                    
                    // 保存token到localStorage
                    if (result.data && result.data.token) {
                        localStorage.setItem('token', result.data.token);
                        localStorage.setItem('user', JSON.stringify(result.data.user));
                    }
                    
                    // 延迟跳转到主页
                    setTimeout(() => {
                        window.location.href = 'index.html';
                    }, 1500);
                    
                } else {
                    // 登录失败
                    showError(result.msg || '登录失败，请检查用户名和密码');
                }
                
            } catch (error) {
                console.error('登录错误:', error);
                showError('网络错误，请稍后重试');
            } finally {
                // 隐藏加载状态
                loading.style.display = 'none';
                loginButton.disabled = false;
                loginButton.textContent = '登录';
            }
        });
        
        // 显示错误消息
        function showError(message) {
            const errorMessage = document.getElementById('errorMessage');
            errorMessage.textContent = message;
            errorMessage.style.display = 'block';
        }
        
        // 显示成功消息
        function showSuccess(message) {
            const successMessage = document.getElementById('successMessage');
            successMessage.textContent = message;
            successMessage.style.display = 'block';
        }
        
        // 检查是否已经登录
        window.addEventListener('load', function() {
            const token = localStorage.getItem('token');
            if (token) {
                // 如果已经登录，跳转到主页
                window.location.href = 'index.html';
            }
        });
        
        // 回车键登录
        document.addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                document.getElementById('loginForm').dispatchEvent(new Event('submit'));
            }
        });
    </script>
</body>
</html>
